/****************************************************
          File Name:main.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat 07 Feb 2015 01:55:28 PM CST
*****************************************************/

#include "circular_linked_list.h"
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    List *list, *list2, *list3;
    int len;

    printf("Enter a list length to initailize: ");
    scanf("%d", &len);
    if(init(&list, len) == ERROR || init(&list2, len) == ERROR)
    {
        fprintf(stderr, "error while init");
        exit(EXIT_FAILURE);
    }

    for(int i=0; i<len; i++)
    {
        printf("Enter a string within 10 charactors: ");
        scanf("%s", list->data);
        list = list->next;
    }

    for(int i=0; i<len; i++)
    {
        printf("list2: ");
        scanf("%s", list2->data);
        list2 = list2->next;
    }

    printf("merge two lists...\n");
    list3 = merge(list, list2);
    printf("show list:\n");

    for(int i=0; i<2*len; i++)
    {
        printf("%s\n", list3->data);
        list3 = list3->next;
    }

    printf("enter a string to inset: ");
    List *va;
    va = (List *)malloc(sizeof(List));
    scanf("%s", va->data);
    insert(list, va);

    for(int i=0; i<2*len+1; i++)
    {
        printf("%s\n", list3->data);
        list3 = list3->next;
    }

    printf("after deleting a member from list:\n");
    rm(&list3);
    for(int i=0; i<2*len; i++)
    {
        printf("%s\n", list3->data);
        list3 = list3->next;
    }

    printf("the length of list: %d\n", listlen(list3));
    destroy(list3);
    return 0;
}
